﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Deanery.Controller.Directories;
using Deanery.Controller.Service;
using Deanery.Controller.StudyData;

namespace Deanery.View
{
    public partial class StudentImportForm : Form
    {
        public StudentImportForm()
        {
            InitializeComponent();
            FillComboBox();
        }

        public void FillComboBox()
        {
            var qualifObj = new QualificationController();
            cmbOKR.DataSource = qualifObj.GetAllQualificationName();

            var naprymObj = new NapryamController();
            cmbDirection.DataSource = naprymObj.GetNapryamName(qualifObj.FindGuidByName(cmbOKR.Text));

            var typeEduObj = new TypeEducationController();
            cmbEduForm.DataSource = typeEduObj.GetAllTypeEducationName();
        }

        
        private void cmbOKR_SelectedIndexChanged(object sender, EventArgs e)
        {
            var obj = new QualificationController();
            var naprymObj = new NapryamController();
            cmbDirection.DataSource = naprymObj.GetNapryamName(obj.FindGuidByName(cmbOKR.SelectedItem.ToString()));
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            var imp = new Import();
            var dataSet = imp.FromExcel();
            
            var person = new PersonController();
            //MessageBox.Show(dataSet.Tables[0].Columns.Count.ToString());
            //MessageBox.Show(dataSet.Tables[0].Rows[0][25].ToString());
            foreach (DataRow item in dataSet.Tables[0].Rows)
            {
                var result = person.SavePerson(item);
                MessageBox.Show(result.ToString());
            }
        }


    }
}
